//
//  String+Extension.swift
//  SinaBlog
//
//  Created by 李超 on 16/3/29.
//  Copyright © 2016年 lichao. All rights reserved.
//

import Foundation

//对String进行拓展，返回正则匹配的结果
extension String{
    
    func linkSource() -> String{
        
      let pattern = ">(.*?)</a>"
        
      let regular = try!NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.DotMatchesLineSeparators)
       let result = regular.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, self.characters.count))
      
        let count = result?.numberOfRanges ?? 0
        var text = "未知来源"
        if count > 0{
          text = (self as NSString).substringWithRange((result?.rangeAtIndex(1))!)
            
        }
        return text
        
    }
    
    
}